using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the ProductDescriptor class.
	/// </summary>
	[Serializable]
	public partial class ProductDescriptorCollection : ActiveList<ProductDescriptor,ProductDescriptorCollection> 
	{	   
		public ProductDescriptorCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Store_ProductDescriptor table.
	/// </summary>
	[Serializable]
	public partial class ProductDescriptor : ActiveRecord<ProductDescriptor>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public ProductDescriptor()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ProductDescriptor(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public ProductDescriptor(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ProductDescriptor(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		public static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Store_ProductDescriptor", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarDescriptorID = new TableSchema.TableColumn(schema);
				colvarDescriptorID.ColumnName = "descriptorID";
				colvarDescriptorID.DataType = DbType.Int32;
				colvarDescriptorID.MaxLength = 0;
				colvarDescriptorID.AutoIncrement = true;
				colvarDescriptorID.IsNullable = false;
				colvarDescriptorID.IsPrimaryKey = true;
				colvarDescriptorID.IsForeignKey = false;
				colvarDescriptorID.IsReadOnly = false;
				colvarDescriptorID.DefaultSetting = @"";
				colvarDescriptorID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescriptorID);
				
				TableSchema.TableColumn colvarProductID = new TableSchema.TableColumn(schema);
				colvarProductID.ColumnName = "productID";
				colvarProductID.DataType = DbType.Int32;
				colvarProductID.MaxLength = 0;
				colvarProductID.AutoIncrement = false;
				colvarProductID.IsNullable = false;
				colvarProductID.IsPrimaryKey = false;
				colvarProductID.IsForeignKey = true;
				colvarProductID.IsReadOnly = false;
				colvarProductID.DefaultSetting = @"";
				
					colvarProductID.ForeignKeyTableName = "CSK_Store_Product";
				schema.Columns.Add(colvarProductID);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 100;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = false;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarDescriptor = new TableSchema.TableColumn(schema);
				colvarDescriptor.ColumnName = "descriptor";
				colvarDescriptor.DataType = DbType.String;
				colvarDescriptor.MaxLength = 2500;
				colvarDescriptor.AutoIncrement = false;
				colvarDescriptor.IsNullable = false;
				colvarDescriptor.IsPrimaryKey = false;
				colvarDescriptor.IsForeignKey = false;
				colvarDescriptor.IsReadOnly = false;
				colvarDescriptor.DefaultSetting = @"";
				colvarDescriptor.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescriptor);
				
				TableSchema.TableColumn colvarIsBulletedList = new TableSchema.TableColumn(schema);
				colvarIsBulletedList.ColumnName = "isBulletedList";
				colvarIsBulletedList.DataType = DbType.Boolean;
				colvarIsBulletedList.MaxLength = 0;
				colvarIsBulletedList.AutoIncrement = false;
				colvarIsBulletedList.IsNullable = false;
				colvarIsBulletedList.IsPrimaryKey = false;
				colvarIsBulletedList.IsForeignKey = false;
				colvarIsBulletedList.IsReadOnly = false;
				
						colvarIsBulletedList.DefaultSetting = @"((0))";
				colvarIsBulletedList.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsBulletedList);
				
				TableSchema.TableColumn colvarListOrder = new TableSchema.TableColumn(schema);
				colvarListOrder.ColumnName = "listOrder";
				colvarListOrder.DataType = DbType.Int32;
				colvarListOrder.MaxLength = 0;
				colvarListOrder.AutoIncrement = false;
				colvarListOrder.IsNullable = false;
				colvarListOrder.IsPrimaryKey = false;
				colvarListOrder.IsForeignKey = false;
				colvarListOrder.IsReadOnly = false;
				
						colvarListOrder.DefaultSetting = @"((1))";
				colvarListOrder.ForeignKeyTableName = "";
				schema.Columns.Add(colvarListOrder);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Store_ProductDescriptor",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("DescriptorID")]
		public int DescriptorID 
		{
			get { return GetColumnValue<int>(Columns.DescriptorID); }

			set { SetColumnValue(Columns.DescriptorID, value); }

		}

		  
		[XmlAttribute("ProductID")]
		public int ProductID 
		{
			get { return GetColumnValue<int>(Columns.ProductID); }

			set { SetColumnValue(Columns.ProductID, value); }

		}

		  
		[XmlAttribute("Title")]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }

			set { SetColumnValue(Columns.Title, value); }

		}

		  
		[XmlAttribute("Descriptor")]
		public string Descriptor 
		{
			get { return GetColumnValue<string>(Columns.Descriptor); }

			set { SetColumnValue(Columns.Descriptor, value); }

		}

		  
		[XmlAttribute("IsBulletedList")]
		public bool IsBulletedList 
		{
			get { return GetColumnValue<bool>(Columns.IsBulletedList); }

			set { SetColumnValue(Columns.IsBulletedList, value); }

		}

		  
		[XmlAttribute("ListOrder")]
		public int ListOrder 
		{
			get { return GetColumnValue<int>(Columns.ListOrder); }

			set { SetColumnValue(Columns.ListOrder, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Product ActiveRecord object related to this ProductDescriptor
		/// 
		/// </summary>
		public Commerce.Common.Product Product
		{
			get { return Commerce.Common.Product.FetchByID(this.ProductID); }

			set { SetColumnValue("productID", value.ProductID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varProductID,string varTitle,string varDescriptor,bool varIsBulletedList,int varListOrder)
		{
			ProductDescriptor item = new ProductDescriptor();
			
			item.ProductID = varProductID;
			
			item.Title = varTitle;
			
			item.Descriptor = varDescriptor;
			
			item.IsBulletedList = varIsBulletedList;
			
			item.ListOrder = varListOrder;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varDescriptorID,int varProductID,string varTitle,string varDescriptor,bool varIsBulletedList,int varListOrder)
		{
			ProductDescriptor item = new ProductDescriptor();
			
				item.DescriptorID = varDescriptorID;
			
				item.ProductID = varProductID;
			
				item.Title = varTitle;
			
				item.Descriptor = varDescriptor;
			
				item.IsBulletedList = varIsBulletedList;
			
				item.ListOrder = varListOrder;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn DescriptorIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn ProductIDColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn DescriptorColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn IsBulletedListColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn ListOrderColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string DescriptorID = @"descriptorID";
			 public static string ProductID = @"productID";
			 public static string Title = @"title";
			 public static string Descriptor = @"descriptor";
			 public static string IsBulletedList = @"isBulletedList";
			 public static string ListOrder = @"listOrder";
						
		}

		#endregion
		
		
		
	}

}

